package com.czy.owner.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.api.DeleteManintenanceApi;
import com.czy.owner.db.UserHelper;
import com.czy.owner.entity.MaintenanceRecord;
import com.czy.owner.net.http.HttpManager;
import com.czy.owner.net.listener.HttpOnNextListener;
import com.czy.owner.utils.DecimalUtil;
import com.czy.owner.utils.PhoneUtils;
import com.czy.owner.utils.StringUtils;
import com.czy.owner.widget.UniversalDialog;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

/**
 * Created by hedepu on 2017/12/21 0001.
 */
public class MaintenanceRecordChildAdapter extends BaseRecyclerAdapter<MaintenanceRecord.DataBeanModel, MaintenanceRecordChildAdapter.MaintenanceRecordChildViewHolder> {
    private int minHeight, maxHeight;

    public MaintenanceRecordChildAdapter(Context context, List<MaintenanceRecord.DataBeanModel> data) {
        super(context, data);
        maxHeight = PhoneUtils.dip2px(context, 60);
        minHeight = PhoneUtils.dip2px(context, 45);
    }

    @Override
    public void onBindViewHolder(MaintenanceRecordChildViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position), position);
    }


    @Override
    public MaintenanceRecordChildViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MaintenanceRecordChildViewHolder(layoutInflater.inflate(R.layout.item_maintenance_record_child_recycler, parent, false));
    }

    public class MaintenanceRecordChildViewHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView tvMaintainType, tvMaintainMoney, tvMaintainBrand, tvMaintainSpecifications;
        private LinearLayout linearMaintainBrand, linearBg;

        public MaintenanceRecordChildViewHolder(View itemView) {
            super(itemView);
            tvMaintainType = (TextView) itemView.findViewById(R.id.tv_maintain_type);
            tvMaintainMoney = (TextView) itemView.findViewById(R.id.tv_maintain_money);
            tvMaintainBrand = (TextView) itemView.findViewById(R.id.tv_maintain_brand);
            tvMaintainSpecifications = (TextView) itemView.findViewById(R.id.tv_maintain_specifications);
            linearMaintainBrand = (LinearLayout) itemView.findViewById(R.id.linear_maintain_brand);
            linearBg = (LinearLayout) itemView.findViewById(R.id.linear_bg);

        }

        public void bindData(final MaintenanceRecord.DataBeanModel mRecord, final int position) {
            tvMaintainType.setText(mRecord.getName() + (StringUtils.isEmpty(mRecord.getNum()) ? "" : "X" + mRecord.getNum()));
            if (mRecord.getIsPack() == 1) {
                tvMaintainMoney.setText("划卡");
            } else {
                tvMaintainMoney.setText(StringUtils.isEmpty(mRecord.getPrice()) ? "" : "¥" + DecimalUtil.formatNum(mRecord.getPrice()));
            }
//            FrameLayout.LayoutParams linearParams = (FrameLayout.LayoutParams) linearBg.getLayoutParams();
            if ("goods".equals(mRecord.getType())) {
                if (StringUtils.isEmpty(mRecord.getBrand())) {
                    tvMaintainBrand.setVisibility(View.GONE);
                } else {
                    tvMaintainBrand.setVisibility(View.VISIBLE);
                    tvMaintainBrand.setText(mRecord.getBrand());
                }
                if (StringUtils.isEmpty(mRecord.getSpe())) {
                    tvMaintainSpecifications.setVisibility(View.GONE);
                } else {
                    tvMaintainSpecifications.setVisibility(View.VISIBLE);
                    tvMaintainSpecifications.setText(mRecord.getSpe());
                }
                linearMaintainBrand.setVisibility(View.VISIBLE);
//                linearParams.height = maxHeight;
            } else {
                // 改变高度

//                linearParams.height = minHeight;

                linearMaintainBrand.setVisibility(View.GONE);
            }
//            linearBg.setLayoutParams(linearParams);
        }

    }
}
